<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>{$Think.lang.mailbox_verification}-{$tpshop_config['shop_info_store_title']}</title>
    <meta name="keywords" content="{$tpshop_config['shop_info_store_keyword']}" />
    <meta name="description" content="{$tpshop_config['shop_info_store_desc']}" />
    <link rel="stylesheet" href="__STATIC__/css/index.css" type="text/css">
    <link rel="stylesheet" href="__STATIC__/css/myuser.css" type="text/css">
</head>

<body>
<!--------头部开始-------------->
<include file="Public/header" />
<include file="Public/topnav" />
<!--------头部结束-------------->

<div class="page_pad">
  <div class="page_margin">
    <div class="page_radius page_hidden">
      <div class="page_padin">
        <div class="user_page">
          <div class="user_poi">当前位置：首页 &gt; <span>邮箱验证</span></div>
          <div class="user_left">
            <include file="User/userleft" />
          </div><!--user_left-->

          <div class="user_right">
            <div class="uright_tit">邮箱验证：</div>
              <form action="" method="post" onSubmit="return check_form();">
                <div style="width:404px;">
                  <!--步骤二 验证新手机号码-->
                  <div class="ginput_div ginput_div_icon"><i class="icon-xinfeng"></i><input class="ginput" type="text" name="old_email" id="old_email" value="{$user_info['email']}" readonly /></div>
                  
                  <div class="ginput_div ginput_div_icon"><i class="icon-xinfeng"></i><input class="ginput" type="text" name="email" id="email" placeholder="{$Think.lang.new_mailbox}" /></div>
                  
                  <div class="ginput_div ginput_div_icon">
                    <div class="fl"><i class="icon-yanzhengma2"></i><input class="ginput" name="code" id="new_code" type="text" placeholder="验证码" /></div>
                    <div class="fr"><button type="button" class="reg_send" id="btnemailAuthCode2" onClick="sendCode(this,'email')">获取验证码</button></div>
                    <div class="clear"></div>
                  </div>
                  <div class="ginput_div"><button type="submit" class="login_sub" id="btn_next">提交</button></div>
                  <!--步骤二 验证新手机号码结束-->
                </div>
            </form>
          </div><!--user_right-->
          <div class="clear"></div>
        </div><!--user_page-->
      </div><!--page_padin-->
    </div><!--page_radius-->
  </div><!--page_margin-->
</div><!--page_pad-->

<script src="__PUBLIC__/js/global.js"></script>
<script src="__PUBLIC__/js/pc_common.js"></script>

<!--------footer-开始-------------->
<include file="Public/footer" />
<!--------footer-结束-------------->
<script>
    // 表单提交验证
    function check_form() {
        var old_email = $('#old_email').val();
        var new_email = $('#email').val();
        //原邮箱不为空的情况下 验证格式
        //240874144@qq.com

        if (old_email != '' && typeof(old_email) != 'undefined') {
            if (!checkEmail(old_email)) {
                layer.alert('原邮箱格式错误', {icon: 2});//alert('原邮箱格式错误');
                return false;
            }
        }

        if (!checkEmail(new_email)) {
            layer.alert('新邮箱格式错误', {icon: 2});//alert('新邮箱格式错误');
            return false;
        }

        if ($.trim($('#new_code').val()) == '') {
            layer.alert('{$Think.lang.code_not_empty} ', {icon: 2});//alert('验证码不能为空');
            return false;
        }
        return true;
    }

    function sendCode(obj, input_id) {
        var id = $(obj).attr('id');
        var input = $('#' + input_id).val();
        var old_email = $('#old_email').val();
        //原邮箱不为空的情况下 验证格式
        if (old_email != '' && typeof(old_email) != 'undefined') {
            if (!checkEmail(old_email)) {
                layer.alert('旧邮箱格式错误 ', {icon: 2});//alert('原邮箱格式错误');
                return false;
            }
        }



        if (!checkEmail(input)) {
            layer.alert('新邮箱格式错误 ', {icon: 2});//alert('邮箱格式错误');
            return false;
        }
        if (input_id == 'old_email')
            var url = "/index.php?m=Home&c=User&a=send_validate_code&step=1&type=email&send=" + input;
        if (input_id == 'new_email')
            var url = "/index.php?m=Home&c=User&a=send_validate_code&step=2&type=email&send=" + input;
        //发送验证码
        $.ajax({
            type: "GET",
            url: url,
            dataType: 'json',
            error: function (request) {
                layer.alert('{$Think.lang.please_contact_admin} ', {icon: 2});//alert("服务器繁忙, 请联系管理员!");
                return;
            },
            success: function (res) {
                if (res.status == 1) {
                    jsInnerTimeout(id);
                } else {
                    layer.alert(res.msg, {icon: 2});//alert('发送失败');
                }
            }
        });
    }

    //倒计时函数
    function jsInnerTimeout(id) {
        var codeObj = $("#" + id);
        var intAs = parseInt(codeObj.attr("IntervalTime"));

        intAs--;
        codeObj.attr("disabled", "disabled");
        if (intAs <= -1) {
            codeObj.removeAttr("disabled");
            codeObj.attr("IntervalTime", 120);
            codeObj.val("{$Think.lang.get_code} ");
            return true;
        }
        codeObj.val(intAs + 's{$Think.lang.again_after_obtaining} ');
        codeObj.attr("IntervalTime", intAs);
        setTimeout("jsInnerTimeout('" + id + "')", 1000);
    }
    ;

</script>
</body>
</html>
